<%--
  Created by IntelliJ IDEA.
  User: CVV
  Date: 2018/6/27
  Time: 9:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <title>订单状态修改 - 物流管理系统</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <style media="all" type="text/css">
        @import "../../style/all.css";
        @import "../../style/jquery/ui.all.css";
    </style>
    <script type="text/javascript" src="../../script/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="../../script/jquery-ui-personalized-1.6rc6.min.js"></script>
    <script type="text/javascript" src="../../script/date.js"></script>
    <script type="text/javascript" src='../../script/common.js'></script>
    <script type="text/javascript">
        var order = null;
        var divContent = "<tr class=\"bg\">\n" +
            "                <td class=\"orderId\"></td>\n" +
            "                <td class=\"date\"></td>\n" +
            "                <td class=\"orderType\"></td>\n" +
            "                <td class=\"orderState\"></td>\n" +
            "                <td id='td-list'>\n" +
            "                    <a class=\"detail\"><img title=\"订单详情\" src=\"../../style/img/detail-ico.png\"/></a>\n" +
            "                    <input class='change' type=\"button\" value=\"改变状态\">\n" +
            "                </td>\n" +
            "            </tr>";

        function checkType(s) {
            if (s == "1")
                return "新订";
            else if (s == "2")
                return "换货";
            else if (s == "3")
                return "退货";
            else if (s == "4")
                return "退订";
            else if (s == "5")
                return "货到付款";
            else if (s == "6") ;
            return "上门收费";
        }

        function addDiv(json) {
            $.each(json, function (index, item) {
                json[index].ordertype = checkType(json[index].ordertype);
                $(".bg").eq(index + 1).find(".orderId").append(json[index].orderid);
                $(".bg").eq(index + 1).find(".date").append(json[index].requireddate);
                $(".bg").eq(index + 1).find(".orderType").append(json[index].ordertype);
                $(".bg").eq(index + 1).find(".orderState").append(json[index].orderstate);
                $(".bg").eq(index + 1).find(".detail").attr("href", "http://localhost:8080/sch_hub/order/linkman.jsp?id=" + json[index].orderid);
            })
        }

        function clearDiv(length, json) {
            for (var k = 1; k < length; k++) {
                $(".bg").eq(1).remove();
            }
            for (var k = 0; k < json.length; k++) {
                $(".bg").eq(0).after(divContent)
            }
        }

        $(function () {
            $.ajax({
                type: "get",
                url: "/lorder/selectAll",
                success(res) {
                    var json = eval(res);
                    $("#counter").text(json.length);
                    var length = $(".bg").length;
                    clearDiv(length, json);
                    addDiv(json);
                },
                error(res) {
                    alert("响应失败，请稍后再试!")
                }
            })
            $(".change").live("click", function () {
                var mythis = $(this);
                if ($(this).parent().parent().find(".orderState").text() == "有货") {
                    alert("此订单已经有存货");
                }
                else {
                    if (confirm("您确认修改么？")) {
                        order = $(this).parent().parent().find(".orderId").text();
                        $.ajax({
                            type: "post",
                            url: "/lorder/updateState",
                            data: {"orderid": order},
                            success(res) {
                                if (res == "1") {
                                    alert("修改成功！");
                                   mythis.parent().parent().find(".orderState").text("有货");
                                }
                            },
                            error(res) {
                                alert("响应失败，请稍后再试")
                            }
                        })
                    }
                }
            })
            datepicker('.date-two');
        });
    </script>
</head>
<body style="background: none">
<div class="top-bar">
    <h1>订单状态修改</h1>
    <div class="breadcrumbs">
        <div class="button-bar">
            <input type="button" name="Submit" value="帮助" class="button" onclick="help('物流管理系统')"/>
            <input type="button" name="Submit" value="查询" class="button"/>
        </div>
        <a href="../../index.jsp" target="_top">首页</a> /
        <a href="../index.jsp" target="_top">调度中心</a>
    </div>
</div>
<div class="select-bar">
    <table class="select-table">
        <tr>
            <th>期望投递日期</th>
            <td style="white-space:nowrap"><input type='text' style='width:75px' class="date-two text" name=''
                                                  readonly/>to<input type='text' style='width:75px'
                                                                     class="date-two text" name='' readonly/></td>
            <th>订单类型</th>
            <td>
                <select style='width:auto'>
                    <option>全部</option>
                    <option>新订</option>
                    <option>换货</option>
                    <option>退货</option>
                    <option>退订</option>
                    <option>货到付款</option>
                    <option>上门收费</option>
                </select>
    </table>
</div>
<div align='right'>
</div>
<div class="table">
    <img src="../../style/img/bg-th-left.gif" width="8" height="7" alt="" class="left"/>
    <img src="../../style/img/bg-th-right.gif" width="7" height="7" alt="" class="right"/>
    <form action='' method='post' name='formTable'>
        <table class="listing" cellpadding="0" cellspacing="0">
            <tr class="bg">
                <th class="first">订单号</th>
                <th>期望投递日期</th>
                <th>订单类型</th>
                <th>订单状态</th>
                <th class="last">操作</th>
            </tr>
        </table>
    </form>
    <div class="pager">
        共<a id="#counter"></a>条记录 每页10条
        第1页/共5页
        <a href="#">第一页</a>
        <a href="#">上一页</a>
        <a href="#">下一页</a>
        <a href="#">最后一页</a>
        转到<input type="text" class="text" size="1" value="1"/>页
        <input type="button" class="button" onclick="" value="GO"/>
    </div>
</div>
</body>
</html>
